package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	const s = "สวัสดี"
	fmt.Println("Lens:", len(s)) //输出lens:18

	for i := 0; i < len(s); i++ {
		fmt.Printf("%x ", s[i])
	}
	//输出：e0 b8 aa e0 b8 a7 e0 b8 b1 e0 b8 aa e0 b8 94 e0 b8 b5
	fmt.Println()

	fmt.Println("Rune count:", utf8.RuneCountInString(s))

	for idx, r := range s {
		fmt.Printf("%d %c\n", idx, r)
	}
	//输出:
	//0 ส
	//1 ว
	//2 ั
	//3 ส
	//4 ด
	//5 ี

	fmt.Println("\nUsing DecodeRuneInString")
	for i, w := 0, 0; i < len(s); i += w {
		runeVaue, width := utf8.DecodeRuneInString(s[i:])
		fmt.Printf("%#U starts at %d \n", runeVaue, i)
		w = width

	}

	// messages := make(chan string, 2)
	// messages <- "buffered"
	// messages <- "channel"
	// messages <- "test"

	// fmt.Printf(<-messages)
	// fmt.Printf(<-messages)
}
